﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Tbl_Usuarios CurrentUser = (Tbl_Usuarios)Session["CurrentUser"];
        if (CurrentUser != null)
        {
            if (CurrentUser.iRol_id == 2)//Admin id type
            {
                //ufv_control.Visible = false;
            }
        }
    }

    public static string formatDate(Object date)
    {
        DateTime current_date = (DateTime)date;
        return current_date.ToString("dd/MM/yyyy"); ;
    }

    public static string getPersonaFromUser(string user)
    {
        ModPersona mod = new ModPersona();
        Tbl_Usuarios c_user = mod.getUsuario(Convert.ToInt32(user));
        Tbl_Personas c_persona = (c_user != null) ? mod.getPersona(c_user.iPersona_id) : null;

        return (c_persona != null) ? c_persona.sNombre + " " + c_persona.sApellido_paterno + " " + c_persona.sApellido_Materno : "null";
    }

    protected void add_Click(object sender, EventArgs e)
    {
        Response.Redirect("CargosForm.aspx");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string squery = txtSearch.Text;
        if (squery != null && squery.Trim() != "")
        {
            ModUFV ufv = new ModUFV();
            Tbl_UFVs c_ufv = ufv.getUFV(txtSearch.Text);
            List<Tbl_UFVs> list = new List<Tbl_UFVs>();
            if (c_ufv != null)
            {
                list.Add(c_ufv);
            }
            grv_selectUFV.DataSource = list;
            grv_selectUFV.DataSourceID = "";//LinqDataSource1
            grv_selectUFV.DataBind();
        }
        else
        {
            grv_selectUFV.DataSourceID = "LinqDataSource1";
            grv_selectUFV.DataSource = null;
            grv_selectUFV.DataBind();
        }
    }
    [WebMethod]
    public static Tbl_UFVs getUFV(string fecha)
    {
        ModUFV ufv = new ModUFV();
        Tbl_UFVs c_ufv = ufv.getUFV(fecha);
        return (c_ufv != null) ? c_ufv : null;
    }

    [WebMethod(EnableSession = true)]
    public static bool saveUFV(string fecha, string valor)
    {

        ModUFV ufv = new ModUFV();
        Tbl_UFVs c_ufv = new Tbl_UFVs();
        Tbl_Usuarios user = (Tbl_Usuarios)HttpContext.Current.Session["CurrentUser"];
        c_ufv.iConcurrencia = 1;
        c_ufv.iEstado_fl = true;
        c_ufv.iValor = Convert.ToDecimal(valor);
        c_ufv.iCreadoPor = (user != null) ? user.iUsuario_id : 0;
        c_ufv.dtFecha = Convert.ToDateTime(fecha);
        return ufv.insertUFV(c_ufv);
    }//fillUFV

    [WebMethod(EnableSession = true)]
    public static bool updateUFV(string fecha, string valor)
    {
        ModUFV ufv = new ModUFV();
        Tbl_UFVs c_ufv = getUFV(fecha);
        Tbl_Usuarios user = (Tbl_Usuarios) HttpContext.Current.Session["CurrentUser"];
        if (c_ufv != null && user != null)
        {
            c_ufv.iValor = Convert.ToDecimal(valor);
            c_ufv.iCreadoPor = user.iUsuario_id;
            ufv.updateUFV(c_ufv);
            return true;
        }
        return false;
    }
}